#ifndef PFS_BLOCK_MAP_H
#define PFS_BLOCK_MAP_H

#include "define.h"
#include "block_locate.h"
#include "server_locate.h"
#include "../utils/Lock.h"

namespace PFS
{
    class BlockMap
    {
        public:
            BlockMap();
            virtual ~BlockMap();
            BlockLocate* find(const uint32_t block_id);
            BlockLocate* create(const uint32_t block_id, bool insert);

            bool exsit(const uint32_t block_id) const;
            bool remove(const uint32_t block_id);
            bool connect(const uint32_t block_id, const uint64_t server_id, const bool is_mater = false);
            bool release(const uint32_t block_id, const uint64_t server_id);
            BlockLocate* insert(const uint32_t block_id, const BlockLocate* block, const bool overwrite = false);//if old exsit, return it
            uint32_t get_max_block_id() const;

            uint64_t get_all_block_bytes() const;

            inline BLOCK_MAP& get_block_map()
            { 
                return block_map;
            }

        private:
            void remove_all();
            BLOCK_MAP block_map;
        public:
            RWLock rw_lock;
    };
}

#endif
